<?php
if(!defined('DCS_ROOT')) {exit('Access Denied');} 

class welcome {

	function __construct() {		
		$this->url = getUrl();
		$action = $this->url['action'];
		require_once(APP_PATH."Model/Admin/Init.php" );
		if($action == 'welcome'){
			$this->defaultAction();
			exit();
		}else{
			error('system error.');
			exit();
		}
	}

	function defaultAction(){
		$tpl = new Template("admin/main/welcome.htm" );		
		$username = $_SESSION['adminuser'];
		$tpl->assign("username", $username);

		$db  = getDB();
		$dbsize = 0;
		$tablepre = DB_PREFIX;
		$result = $db->query("SHOW TABLE STATUS LIKE '%'", 'SILENT');
		while($table = $db->fetchRow($result)) {
			$dbsize += $table['Data_length'] + $table['Index_length'];
		}

		$sql = $db->query("SELECT * FROM admin WHERE adminuser = '$username' ");		
		$username = $db->fetchRow($sql);		
		$globalVar['lasttime'] = date("Y-m-d H:i:s",$username['logintime']);
		$globalVar['lastip'] = $username['loginip'];
		$globalVar['loginnum'] = $username['loginnum'];

		$result = $db->query("SELECT count(*) AS total FROM movie ");		
		$db->fetchRow($result);
		$globalVar['movie'] = $db->getValue("total");
		
		$globalVar['now_time'] = date("Y-m-d H:i:s",time());


		if (function_exists(gd_info)) {
			$gd = gd_info();
			$gd_version = $gd['GD Version'];
		} else {
			$gd_version = '不清楚';
		}

		$globalVar['server_software'] = $_SERVER['SERVER_SOFTWARE'];
		$globalVar['fileupload'] = @ini_get("file_uploads") ? "<font color=green>文件&nbsp;".ini_get("upload_max_filesize").'<b>√</b></font>' : "<font color=\"red\">禁止<b>×</b></font>";
		$globalVar['globals'] = get_cfg_var('register_globals') ? '<font color=red>打开<b>×</b></font>' :'<font color=green>关闭<b>√</b></font>';
		$globalVar['safe_mode'] = get_cfg_var('safe_mode') ? '<font color=red>打开<b>×</b></font>' :'<font color=green>关闭<b>√</b></font>';
		$globalVar['gd_version'] = $gd_version;
		$globalVar['dbsize'] = $dbsize ? $this->get_size($dbsize) : '不清楚';
		$globalVar['dbver'] = mysql_get_server_info();
		$globalVar['domain'] = $_SERVER['SERVER_NAME'];//主机名
		$globalVar['ip'] = getenv(SERVER_ADDR);
		$globalVar['os'] = PHP_OS; //服务器操作系统
		$globalVar['phpver'] = PHP_VERSION;//php版本
		$globalVar['zendVer'] = zend_version();//服务器语种
		$globalVar['disk'] = intval(diskfreespace(".") / (1024 * 1024))."M"; //服务器空间大小

		$globalVar['smtp'] = $this->is_true(get_magic_quotes_gpc("smtp"));//SMTP
		$globalVar['memory'] = get_cfg_var("memory_limit")?get_cfg_var("memory_limit"):"无"; //单个脚本运行时可占用的最大内存
		$globalVar['max_execution_time'] = get_cfg_var("max_execution_time")."秒"; //脚本超时时间
		$globalVar['ftp'] = $this->is_true(get_magic_quotes_gpc("FTP support"));//FTP 支持
		$globalVar['session'] = $this->is_true(function_exists("session_start")); //Session支持
		$globalVar['Zlib'] = $this->is_true(function_exists("gzclose")); //压缩文件支持(Zlib)
		$globalVar['url_fopen'] = $this->is_true(get_cfg_var("allow_url_fopen"));//允许使用URL打开文件
		$tpl->assign($globalVar);		
		$tpl->output();
	}
	
	function is_true($temp){
		if($temp == 1){
			$s='<font color=green>支持<b>√</b></font>';
		}else{
			$s='<font color=red>不支持<b>×</b></font>';
		}
		return $s;
	}	
	function get_size($size) {
		if($size < 1024) { 
			return $size.'B';
		}else if($size < 1048576) { 
			return round($size/1024,2).'KB';
		}else if($size < 1073741824) {	
			return round($size/1048576,2).'MB';
		}else {
			return round($size/1073741824,2).'GB';
		}
	}

}
?>
